//
//  ConfigScriptViewController+Layout.swift
//  Hermes
//
//  Created by FH on 2021/1/19.
//  Copyright © 2021 Agora. All rights reserved.
//

import Foundation
// TODO: remove
extension ConfigScriptViewController {
    func buildAPIsSearchView() {
        let bgView = NSView()
        bgView.bind(to: yoga, self.view) { it in
            it.direction = .row
            it.height = constAPIsSearchViewHeight.toFLValue()
            it.alignItems = .center
        }
        bgView.flBackgroundColor = .white
        
        let line = NSView()
        line.bind(to: yoga, bgView) { it in
            it.position = .absolute
            it.height = 0.5
            it.left = 8
            it.right = 8
            it.bottom = 0.5
        }
        line.flBackgroundColor = .darkGray
        
        self.bodyView.bind(to: yoga, self.view) { it in
            it.flexGrow = 1
            it.direction = .row
        }
        
        self.selectCategory.bind(to: yoga, bgView) { it in
            it.width = 120
            it.height = 30
            it.marginLeft = 4
        }
        
        // search info div
        let searchInfoDiv = NSView()
        searchInfoDiv.bind(to: yoga, bgView) { it in
            it.direction = .row
            it.paddingHorizontal = 18
            it.flexGrow = 1
        }
        
        // left part
        let leftPart = NSView()
        leftPart.bind(to: yoga, searchInfoDiv) { it in
            it.direction = .row
        }
        
        self.selectAPIsType.bind(to: yoga, leftPart) { it in
            it.width = 120
            it.height = 30
        }
        
        self.inputSearch.bind(to: yoga, leftPart) { it in
            it.width = 280
            it.height = 24
            it.marginLeft = 4
        }
        self.inputSearch.font = NSFont.systemFont(ofSize: 14)
        
        self.btnSearch.bind(to: yoga, leftPart) { it in
            it.width = 80
            it.height = 26
            it.marginLeft = 8
        }
        self.btnSearch.flTitle = "search"
        self.btnSearch.flTitleColor = .white
        self.btnSearch.flBackgroundColor = .darkGray
        self.btnSearch.flCornerRadius = 4
        
        // center part
        let centerPart = NSView()
        centerPart.bind(to: yoga, searchInfoDiv) { it in
            it.alignItems = .center
            it.flexGrow = 1
        }
        
        let dividingLine = NSView()
        dividingLine.bind(to: yoga, centerPart) { it in
            it.marginVertical = 2
            it.flexGrow = 1
            it.width = 0.5
        }
        dividingLine.flBackgroundColor = .darkGray
        
        // right part
        let rightPart = NSView()
        rightPart.bind(to: yoga, searchInfoDiv) { it in
            it.direction = .row
            it.width = 480
        }
        
        for select in self.associatedSelects {
            select.bind(to: yoga, rightPart) { it in
                it.width = 160
                it.height = 30
            }
        }
        // buttons div
        let buttonsDiv = NSView()
        buttonsDiv.bind(to: yoga, bgView) { it in
            it.direction = .rowReverse
            it.paddingRight = 8
            it.alignItems = .center
        }
        
        self.btnAttach.bind(to: yoga, buttonsDiv) { it in
            it.width = 80
            it.height = 26
            it.marginLeft = 6
        }
        self.btnAttach.flTitle = "Attach To"
        self.btnAttach.flTitleColor = .darkGray
        self.btnAttach.flBackgroundColor = .lightGray
        self.btnAttach.flCornerRadius = 4
        self.btnAttach.isEnabled = false

        self.btnSave.bind(to: yoga, buttonsDiv) { it in
            it.width = 80
            it.height = 26
            it.marginLeft = 6
        }
        self.btnSave.flTitle = "Save"
        self.btnSave.flTitleColor = .white
        self.btnSave.flBackgroundColor = .orange
        self.btnSave.flCornerRadius = 4

        self.btnCancel.bind(to: yoga, buttonsDiv) { it in
            it.width = 80
            it.height = 26
        }
        self.btnCancel.flTitle = "Cancel"
        self.btnCancel.flTitleColor = .darkGray
        self.btnCancel.flBackgroundColor = .lightGray
        self.btnCancel.flCornerRadius = 4
    }
    
    func buildTableScriptView() {
        let bgView = NSView()
        bgView.bind(to: yoga, self.bodyView) { it in
            it.width = 360
        }
        bgView.flBackgroundColor = .lightGray
    }
    
    func buildTableAPIsView() {
//        let bgView = NSView()
//        bgView.bind(to: yoga, self.bodyView) { it in
//            it.flexGrow = 1
//        }
        // TODO: use absolute
        self.tblAPIs.bind(to: yoga, self.bodyView) { it in
//            it.position = .absolute
            it.flexGrow = 1
        }
    }
    
    func buildEditParamsView() {
        let bgView = NSView()
        bgView.bind(to: yoga, self.bodyView) { it in
            it.width = (self.view.frame.size.width * 0.3).toFLValue()
        }
        bgView.flBackgroundColor = .lightGray
    }
}
